package com.li.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.ndboo.reslibrary.R;

/**
 * Author: Li
 * Date: 2017/8/8
 * Description:
 */

public class ImageTextVertical extends FrameLayout {
    public ImageView getImageView() {
        return mImageView;
    }

    private ImageView mImageView;
    private TextView mTextView;

    public ImageTextVertical(@NonNull Context context) {
        super(context);
    }

    public ImageTextVertical(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        View view = LayoutInflater.from(context)
                .inflate(R.layout.layout_img_txt_vertical, this);
        mImageView = (ImageView) view.findViewById(R.id.img);
        mTextView = (TextView) view.findViewById(R.id.txt);


        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.ImageTextVertical);
        int img = array.getResourceId(R.styleable.ImageTextVertical_imgVertical, -1);
        String txt = array.getString(R.styleable.ImageTextVertical_txtVertical);
        array.recycle();
        if (img != -1) {
            mImageView.setImageResource(img);
        }
        mTextView.setText(txt);
    }

    public void setText(String text) {
        mTextView.setText(text);
    }
}
